package com.tarena.lbs.article.web.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 读取spring.elasticsearch.uris 构造一个restHighLevelClient
 */
@Configuration
public class ESRestClientConfig {
    //读取属性
    @Value("${spring.elasticsearch.uris}")
    private String uris;
    @Bean
    public RestHighLevelClient initESClient(){
        HttpHost httpHost = HttpHost.create(uris);//传递是带有协议的uri地址
        RestClientBuilder builder = RestClient.builder(httpHost);
        return new RestHighLevelClient(builder);
    }
}
